package com.py.credit.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.SysUser;
import com.py.credit.entity.TableResult;
import com.py.credit.service.CreditViewService;
import com.py.credit.service.SSearchService;
import com.py.credit.service.ScontentService;
import com.py.framework.core.annotation.IgnoreAuthority;
import com.py.framework.core.helper.HttpServletHelper;

@RestController
@RequestMapping("/creditViewController")
public class CreditViewController {

    @Autowired
    private ScontentService sContentService;

    @Autowired
    private SSearchService sSearchService;
    
	@Autowired
	private CreditViewService creditViewService;
	/**
	 * 数据归集总览
	 */
	@IgnoreAuthority
	@RequestMapping("/dataCollection.json")
	public RestServiceResult<List<Map<String, Object>>> dataCollection(
			) {
		//获取数据
		List<Map<String, Object>> tableList = creditViewService.getTableList();

		return new RestServiceResult<List<Map<String, Object>>>(tableList);

	}
	/**
	 * 数据归集总览
	 */
	@IgnoreAuthority
	@RequestMapping("/dataNum.json")
	public RestServiceResult<List<Map<String, Object>>> dataNum(
			) {
		//获取数据
		List<Map<String, Object>> tableList = creditViewService.getdataNum();

		return new RestServiceResult<List<Map<String, Object>>>(tableList);

	}
	/**
	 * 信用预警
	 */
	@IgnoreAuthority
	@RequestMapping("/creditWarnData.json")
	public RestServiceResult<List<Map<String, String>>> creditWarnData(
			) {
		//获取数据
		List<Map<String, String>> tableList = creditViewService.getcreditWarnData();

		return new RestServiceResult<List<Map<String, String>>>(tableList);

	}
	/**
	 * 信用信息全景查询企业信息
	 */
	@IgnoreAuthority
	@RequestMapping("/creditviewSelect.json")
	public RestServiceResult<List<Object>> creditviewSelect(
			@RequestParam(value = "tybm", defaultValue = "", required = true) String tybm,
            @RequestParam(value = "kId", defaultValue = "", required = true) String kId,
            @RequestParam(value = "keyWord", defaultValue = "", required = true) String keyWord) {
		//获取数据
		List<Object> tableList = creditViewService.getcreditviewSelect(tybm,kId,keyWord);

		return new RestServiceResult<List<Object>>(tableList);

	}
		/**
		 * 
		 * @Title: getDetail
		 * @Description: TODO(企业详情)
		 * @param @param tybm
		 * @param @param kId
		 * @param @param keyWord
		 * @param @param request
		 * @param @return    设定文件
		 * @return RestServiceResult<Object>    返回类型
		 * @throws
		 */
	 @IgnoreAuthority
	    @SuppressWarnings("unchecked")
	    @RequestMapping(value = "/getDetail.json")
	    public RestServiceResult<Object> getDetail(
	            @RequestParam(value = "tybm", defaultValue = "", required = true) String tybm,
	            @RequestParam(value = "kId", defaultValue = "", required = true) String kId,
	            @RequestParam(value = "keyWord", defaultValue = "", required = true) String keyWord,
	            HttpServletRequest request) {	     
	        SysUser userInfo = new SysUser();	       
	        userInfo.setId(1L);
	        userInfo.setUsername("admin");
	        userInfo.setRoleName("系统管理员");
	        userInfo.setOfficeId(51);
	        Map<String, Object> detail = sContentService.getDetail(kId, tybm, "YZS", userInfo);
	        // 根据样式展示
	        List<TableResult> data = sSearchService.assembleTableComponentForYZS((List<TableResult>) detail.get("results"));

	        return new RestServiceResult<Object>(data);

	    }
	/**
	 * 根据传递参数查询基础表是否存在相关信息
	 */
	@IgnoreAuthority
	@RequestMapping("/checkfromPlatform.json")
	public RestServiceResult<Long> checkfromPlatform(			
            @RequestParam(value = "ztmc", defaultValue = "", required = true) String ztmc,
            @RequestParam(value = "bm", defaultValue = "", required = true) String bm,
            @RequestParam(value = "fddbr", defaultValue = "", required = true) String fddbr,
            @RequestParam(value = "fddbrzjhm", defaultValue = "", required = true) String fddbrzjhm,
            @RequestParam(value = "tablename", defaultValue = "", required = true) String tablename,
            @RequestParam(value = "type", defaultValue = "", required = true) String type ) {
		
		List<Map<String,Long>> map = new ArrayList<Map<String, Long>>();
	
		//获取数据
		if(type.equals("C")) {
			map = creditViewService.checkfromPlatformFr(ztmc,bm,fddbr,fddbrzjhm,tablename);
		}else {
			map = creditViewService.checkfromPlatformZrr(ztmc,bm,tablename);
		}
		

		return new RestServiceResult<Long>(map.get(0).get("count"));

	}
	
	/**
	 * 信用信息全景查询企业信息
	 */
	@IgnoreAuthority
	@RequestMapping("/getAllLonAndLat.json")
	public RestServiceResult<List<Object>> getAllLonAndLat(
			) {
		//获取数据
		List<Object> tableList = creditViewService.getAllLonAndLat();

		return new RestServiceResult<List<Object>>(tableList);

	}
	

	/**
	 * 信用信息全景查询企业信息行业分布
	 */
	@IgnoreAuthority
	@RequestMapping("/getHyFb.json")
	public RestServiceResult<List<Object>> getHyFb(
			) {
		//获取数据
		List<Object> tableList = creditViewService.getHyFb();

		return new RestServiceResult<List<Object>>(tableList);

	}
	
	/**
	 * 	可视化大屏首页数据归集
	 * @Title: dataSyCollection
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @return    设定文件
	 * @return RestServiceResult<List<Object>>    返回类型
	 * @throws
	 */
	@IgnoreAuthority
	@RequestMapping("/dataSyCollection.json")
	public RestServiceResult<Object> dataSyCollection(
			) {
		//获取数据
		Object tableList = creditViewService.dataSyCollection();

		return new RestServiceResult<Object>(tableList);

	}
	
	@IgnoreAuthority
	@RequestMapping("/qyOverview.json")
	public RestServiceResult<Object> qyOverview(String tybm
			) {
		//获取数据
		Object tableList = creditViewService.getqyOverview(tybm);

		return new RestServiceResult<Object>(tableList);

	}
	
}
